clear
clear matrix
set more off

* ______________________________________________________________________________
* REGRESSIONS FOR FIGURE 6a

use "[ENERGY DATA - FULL PANEL]", clear
keep if conversions == 0 | (conversions == 1 & wg == "SF")

keep wuse* euse year month tau conversions id appdate housesf
set matsize 500

* generate event time relative to application date
gen apptau = 12*(year - year(appdate)) + month - month(appdate) if conversions == 1
tab tau if apptau == 0

* make sample as small as possible
compress
sort id

* event study regressions: relative to application date
local ewin = 36 // define event window
*** create event dummies
* lag dummies
foreach t of numlist `ewin'/1 {
local id = `t'
gen byte appD_n`id' = 0
replace appD_n`id' = 1 if apptau == -`t'
}
* lead dummies
foreach t of numlist 0/`ewin' {
local id = `t'
gen byte appD_p`id' = 0
replace appD_p`id' = 1 if apptau == `t'
}

* create the bumper dummies
replace appD_n`ewin' = 1 if apptau < -`ewin' & conversions == 1
replace appD_p`ewin' = 1 if apptau >  `ewin' & conversions == 1

reghdfe euse appD_n`ewin'-appD_n1 appD_p1-appD_p`ewin' i.year#i.month ///
	if conversions == 0 | ///
	(conversions == 1 & inrange(apptau, -`ewin', `ewin')),	a(id) vce(cl id)
display "command line: `e(cmdline)'"
estimates save "$output/ep1_es_apptau_ew`ewin'_pFEymFE.ster", replace

log close save_eventstudy

* ______________________________________________________________________________
* REGRESSIONS FOR FIGURE 6b

use "[ENERGY DATA - MATCHED PANEL]", clear
keep wuse* euse year month tau conversions id housesf appdate parcelfreq

set matsize 500

* generate event time relative to application date
gen apptau = 12*(year - year(appdate)) + month - month(appdate) if conversions == 1
tab tau if apptau == 0

* make sample as small as possible
compress
sort id year month

* event study regressions: relative to application date
local ewin = 36 // define event window
*** create event dummies
* lag dummies
foreach t of numlist `ewin'/1 {
local id = `t'
gen byte appD_n`id' = 0
replace appD_n`id' = 1 if apptau == -`t'
}
* lead dummies
foreach t of numlist 0/`ewin' {
local id = `t'
gen byte appD_p`id' = 0
replace appD_p`id' = 1 if apptau == `t'
}

* create the bumper dummies
replace appD_n`ewin' = 1 if apptau < -`ewin' & conversions == 1
replace appD_p`ewin' = 1 if apptau >  `ewin' & conversions == 1

reghdfe euse appD_n`ewin'-appD_n1 appD_p1-appD_p`ewin' i.year#i.month ///
	if conversions == 0 | ///
	(conversions == 1 & inrange(apptau, -`ewin', `ewin')) ///
	[fweight=parcelfreq], a(id) vce(cl id)
display "command line: `e(cmdline)'"
estimates save "$output/ep1_esmatch_apptau_ew`ewin'_pFEymFE.ster", replace